package org.pp.controller;

import io.swagger.v3.oas.annotations.Operation;
import org.pp.admin.dto.InfoUpdate;
import org.pp.admin.dto.Login;
import org.pp.admin.dto.PasswordUpdate;
import org.pp.core.Result;
import org.pp.service.ISysLoginService;
import org.pp.vo.AdminLoginCodeVo;
import org.pp.vo.AdminLoginVo;
import org.pp.vo.AdminUserInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
public class SysLoginController {

    @Autowired
    ISysLoginService loginService;

    @GetMapping("/login/code")
    @Operation(summary = "获取验证码")
    public Result<AdminLoginCodeVo> getCode(){
        AdminLoginCodeVo vo=  loginService.getCode();
        return Result.ok(vo);
    }

    @PostMapping("/login")
    @Operation(summary = "登录")
    public Result<AdminLoginVo> login(@RequestBody @Validated Login dto){
        AdminLoginVo vo=  loginService.login(dto);
        return Result.ok(vo);
    }

    @PostMapping("/logout")
    @Operation(summary = "注销登录")
    public Result<Void> logout(){
          loginService.logout();
        return Result.ok();
    }

    @PostMapping("/sys/password/update")
    @Operation(summary = "修改密码")
    public Result<Void> passwordUpdate(@RequestBody @Validated PasswordUpdate dto){
        loginService.passwordUpdate(dto);
        return Result.ok();
    }

    @PostMapping("/sys/info/update")
    @Operation(summary = "修改信息")
    public Result<Void> infoUpdate(@RequestBody @Validated InfoUpdate dto){
        loginService.infoUpdate(dto);
        return Result.ok();
    }

    @GetMapping("/sys/info")
    @Operation(summary = "获取信息")
    public Result<AdminUserInfoVo> userInfo(){
        AdminUserInfoVo vo=  loginService.userInfo();
        return Result.ok(vo);
    }

}
